package com.logictech.lims.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import com.logictech.lims.service.GlasswareService;
import com.logictech.lims.service.GlasswareTypeService;
import com.logictech.lims.service.LogService;
import com.logictech.lims.entity.Glassware;
import com.logictech.lims.entity.GlasswareType;
import com.logictech.lims.dao.GlasswareDao;
import com.logictech.lims.dto.GlasswareDto;

@Service("glasswareService")
public class GlasswareServiceImpl implements GlasswareService {
	@Resource
	private GlasswareDao glasswareDao;
	
	@Resource
	GlasswareTypeService glasswareTypeService;
	
	@Resource
	private LogService logService;

	@Override
	public void doAdd(Glassware glassware) {
		glasswareDao.add(glassware);
		logService.doAdd("1",glassware);
	}

	@Override
	public void doEdit(Glassware glassware) {
		glasswareDao.update(glassware);
		logService.doAdd("2",glassware);
	}

	@Override
	public void doDelete(String id) {
		Glassware glassware  = glasswareDao.get(id);
		
		GlasswareType glasswareType = glasswareTypeService.queryById(glassware.getGlasswareTypeId().toString());
		String strGlasswareType = "";
		strGlasswareType += glasswareType.getSize() + "ml";
		if("1".equals(glasswareType.getType())){
			strGlasswareType += "容量瓶";
		}else if("2".equals(glasswareType.getType())){
			strGlasswareType += "移液管";
		}else if("3".equals(glasswareType.getType())){
			strGlasswareType += "刻度吸管";
		}else if("4".equals(glasswareType.getType())){
			strGlasswareType += "量筒";
		}
		glassware.setGlasswareType(strGlasswareType);
		logService.doAdd("3",glassware);
		glasswareDao.delete(id);
	}

	@Override
	public Glassware queryById(String id) {
		Glassware glassware  = glasswareDao.get(id);
		return glassware;
	}

	@Override
	public PageList<GlasswareDto> queryPageList(
		PageQuery<GlasswareDto> pageQuery) {
		PageList<GlasswareDto> result = new PageList<GlasswareDto>();
		Integer itemCount = glasswareDao.count(pageQuery);
		List<GlasswareDto> list = glasswareDao.queryPageList(pageQuery,itemCount);
		Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
		result.setPagenation(pagenation);
		result.setValues(list);
		return result;
	}

	@Override
	public int getMaxNo(String no) {
		return glasswareDao.getMaxNo(no);
	}

	@Override
	public List<GlasswareDto> queryList(PageQuery<GlasswareDto> pageQuery) {
		return glasswareDao.queryList(pageQuery);
	}
	
	@Override
	public Integer countByNo(String no) {
		return glasswareDao.countByNo(no);
	}
	
}
